package com.mobimagic.lockscreen.remaintime.aidl;

import android.os.Parcel;
import android.os.Parcelable;

public class ChargingData implements Parcelable {

    private int chargePlugin;

    /**
     * 1代表yes
     */
    private int isCharging;

    /**
     * 建议斜率
     */
    private double suggestSlope;

    /**
     * 真斜率
     */
    private double slope;

    /**
     * 秒，离开始的时间
     */
    private int time;
    /**
     * 电量
     */
    private int battery;
    /**
     * 分钟
     */
    private int remainder = 0;

    public double getSlope() {
        return slope;
    }

    public void setSlope(double slope) {
        this.slope = slope;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getBattery() {
        return battery;
    }

    public void setBattery(int battery) {
        this.battery = battery;
    }

    public int getRemainder() {
        return remainder;
    }

    public void setRemainder(int remainder) {
        this.remainder = remainder;

    }

    public int getEndTime() {
        return time + remainder;
    }

    public ChargingData(int time, int battery) {
        super();
        this.time = time;
        this.battery = battery;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public double getSuggestSlope() {
        return suggestSlope;
    }

    public void setSuggestSlope(double suggestSlope) {
        this.suggestSlope = suggestSlope;
    }

    public int getChargePlugin() {
        return chargePlugin;
    }

    public void setChargePlugin(int chargePlugin) {
        this.chargePlugin = chargePlugin;
    }

    public void setCharging(boolean isCharging) {
        this.isCharging = isCharging ? 1 : 0;
    }

    public boolean isCharging() {
        return isCharging == 1;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(chargePlugin);
        dest.writeInt(isCharging);
        dest.writeInt(time);
        dest.writeInt(battery);
        dest.writeInt(remainder);
        dest.writeDouble(slope);
        dest.writeDouble(suggestSlope);

    }

    public static final Parcelable.Creator<ChargingData> CREATOR = new Creator<ChargingData>() {
        @Override
        public ChargingData[] newArray(int size) {
            return new ChargingData[size];
        }

        @Override
        public ChargingData createFromParcel(Parcel source) {
            int plug = source.readInt();
            boolean isCharging = source.readInt() == 1;
            int time = source.readInt();
            int battery = source.readInt();
            ChargingData chargingData = new ChargingData(time, battery);
            chargingData.setRemainder(source.readInt());
            chargingData.setSlope(source.readDouble());
            chargingData.setSuggestSlope(source.readDouble());
            chargingData.setChargePlugin(plug);
            chargingData.setCharging(isCharging);
            return chargingData;
        }
    };
}
